package com.hankol.winecellar.adapter

import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.extension.load
import com.baselibrary.utils.CommonUtil
import com.baselibrary.view.RoundCornerImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.PrivateMealManageListBean
import com.hankol.winecellar.bean.WineryCoverBean
import com.xinlan.imageeditlibrary.editimage.utils.DensityUtil

/*私房菜 列表
* */
class PrivateMealNormalAdapter : BaseQuickAdapter<PrivateMealManageListBean, BaseViewHolder>(R.layout.item_private_meal_normal) {


    override fun convert(helper: BaseViewHolder, item: PrivateMealManageListBean) {
        helper.apply {
            if (item.appetizerImg.checkValue().checkNotNull()) {
                val wineryCoverBean = CommonUtil.jsonToBean(item.appetizerImg.checkValue(), WineryCoverBean::class.java)
                setGone(R.id.iv_play, wineryCoverBean.type == 1)
                getView<RoundCornerImageView>(R.id.rimg_cover).load(mContext, if (wineryCoverBean.type == 0) wineryCoverBean.coverUrl.checkValue() else wineryCoverBean.videoUrl)
            }
            setGone(R.id.tv_rank, adapterPosition == 0 || adapterPosition == 1 || adapterPosition == 2)
            setText(R.id.tv_rank, "TOP${adapterPosition.plus(1)}")
            setText(R.id.tv_name, item.appetizerName.checkValue())
            val rlRoot = getView<RelativeLayout>(R.id.rl_root)
            val layoutParams = rlRoot.layoutParams as RecyclerView.LayoutParams
            layoutParams.rightMargin = DensityUtil.dip2px(mContext, if (helper.adapterPosition == data.size - 1) 14f else 0f)
            layoutParams.leftMargin = DensityUtil.dip2px(mContext, if (helper.adapterPosition == 0) 4f else 0f)
            rlRoot.layoutParams = layoutParams
        }
    }
}